package com.ctshk.sapp.hotel.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.hotel.dto.HotelRoomTypeDTO;
import com.ctshk.rpc.hotel.dto.HotelRoomTypeManagerListDTO;
import com.ctshk.rpc.hotel.req.HotelRoomTypeEditReq;
import com.ctshk.rpc.hotel.req.HotelRoomTypeManagerListReq;
import com.ctshk.rpc.hotel.req.HotelRoomTypeReq;
import com.ctshk.rpc.hotel.service.IHotelRoomFacilitiesService;
import com.ctshk.rpc.hotel.service.IHotelRoomTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 酒店房型 前端控制器
 * </p>
 *
 * @author yinhuan
 * @since 2021-03-03
 */
@RestController
@Api(value = "酒店房型管理", tags = "酒店房型管理")
@RequestMapping("/hotel/roomtype")
public class HotelRoomTypeController extends BaseController {
    @DubboReference
    private IHotelRoomTypeService hotelRoomTypeService;
    @DubboReference
    private IHotelRoomFacilitiesService hotelRoomFacilitiesService;

    @ApiOperation(value = "酒店房型管理列表查询", notes = "酒店房型管理列表查询")
    @PostMapping(value = "/querylist")
    public Result<PageResponse<HotelRoomTypeManagerListDTO>> queryList(@RequestBody @Valid HotelRoomTypeManagerListReq hotelRoomTypeManagerListReq) {

        return Result.success(hotelRoomTypeService.queryList(hotelRoomTypeManagerListReq));
    }

    @ApiOperation(value="新增酒店房型", notes="新增酒店房型")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增巴士产品", operDesc = "新增巴士产品")
    @PostMapping("/save")
    public Result saveBusProduct(@RequestBody @Valid HotelRoomTypeReq hotelRoomTypeReq) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelRoomTypeService.saveHotelRoomType(hotelRoomTypeReq,user);
    }

    @ApiOperation(value="编辑酒店房型", notes="编辑酒店房型")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "编辑代理商", operDesc = "编辑代理商")
    @PostMapping("/edit")
    public Result editAgent(@RequestBody HotelRoomTypeReq hotelRoomTypeReq){
        return hotelRoomTypeService.updateHotelRoomType(hotelRoomTypeReq,getCurrentUser(getRequest()).getId());
    }

    @ApiOperation(value="根据id查询酒店房型详情", notes="根据id查询酒店房型详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "根据id查询代理商详情", operDesc = "根据id查询代理商详情")
    @GetMapping("/info/{id}")
    public Result<HotelRoomTypeDTO> query(@PathVariable Long id){
        return hotelRoomTypeService.query(id);
    }
}
